﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace theeg.DependencyAnalysis.CommonAddin.Models
{
    [Serializable]
    [DataContract(IsReference = true)]
    public class RuleDescriptor : IRuleDescriptor, INotifyPropertyChanged
    {
        private RunState _state;
        private string _name;
        private string _source;
        private string _results;
        private string _category;

        [DataMember]
        public RunState State
        {
            get { return _state; }
            set
            {
                _state = value;
                RaisePropertyChanged("State");
            }
        }

        public string Results
        {
            get { return _results; }
            set
            {
                _results = value;
                RaisePropertyChanged("Results");                
            }
        }

        [DataMember]
        public string Category
        {
            get { return _category; }
            set
            {
                _category = value;
                RaisePropertyChanged("Category");
            }
        }

        [DataMember]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        [DataMember]
        public string Source
        {
            get { return _source; }
            set
            {
                _source = value;
                RaisePropertyChanged("Source");
            }
        }

        public ICompiledRule Compiled { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
